/**
  **************************************************************************
  * @file     main.c
  * @version  v2.3.0
  * @date     2022-06-09
  * @brief    main program
  **************************************************************************
  *                       Copyright notice & Disclaimer
  *
  * The software Board Support Package (BSP) that is made available to
  * download from Artery official website is the copyrighted work of Artery.
  * Artery authorizes customers to use, copy, and distribute the BSP
  * software and its related documentation for the purpose of design and
  * development in conjunction with Artery microcontrollers. Use of the
  * software is governed by this copyright notice and the following disclaimer.
  *
  * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  *
  **************************************************************************
  */

#include "at32f403a_407_board.h"
#include "dev_st7789v.h"

#include "task_lvgl.h"
#include "task_key.h"
#include "task_gnss.h"

#include "FreeRTOS.h"
#include "task.h"

#include "main.h"

notify_list_t* notify_gps_list = NULL;

static void notify_init(void);
extern void SPI1_DMA_CB(void);
/**
  * @brief  main function.
  * @param  none
  * @retval none
  */
int main(void)
{
	at32_board_init();
	
	/* st7789 init */
	st7789_init(SPI1_DMA_CB);
	
  /* enter critical */
  taskENTER_CRITICAL();
	
	notify_init();
	printf_xmutex_init();
	lv_signal_init();
	gps_signal_init();
  /* create task_lvgl task */
	xTaskCreate((TaskFunction_t )task_lvgl,
                 (const char*    )"task_lvgl",
                 (uint16_t       )1024,
                 (void*          )NULL,
                 (UBaseType_t    )2,
                 (TaskHandle_t*  )&app_lvgl_handler);
								 
	xTaskCreate((TaskFunction_t )task_key,
                 (const char*    )"task_key",
                 (uint16_t       )256,
                 (void*          )NULL,
                 (UBaseType_t    )2,
                 (TaskHandle_t*  )&app_key_handler);
								 
	xTaskCreate((TaskFunction_t )task_gnss,
                 (const char*    )"task_gnss",
                 (uint16_t       )512,
                 (void*          )NULL,
                 (UBaseType_t    )2,
                 (TaskHandle_t*  )&app_gnss_handler);
  /* exit critical */
  taskEXIT_CRITICAL();

  /* start scheduler */
  vTaskStartScheduler();
}

static void notify_init(void)
{
		notify_gps_list = task_notify_init();
}

/**
  * @}
  */
